<?php

/**
 * mainpage actions.
 *
 * @package    sf_sandbox
 * @subpackage mainpage
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class mainpageActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  	
  	
  	$this->setDecorator();
     $this->mat = MaterialPeer::retrieveByPK(1);
	     if($this->mat){
       ////Устанавливаем заголовки
		  	$this->getResponse()->addMeta('description',  $this->mat->getSeoIDescription());
		    $this->getResponse()->addMeta('keywords', $this->mat->getSeoIkeyword());
		    $this->getResponse()->addMeta('title',  $this->mat->getSeoItitle());
	   ////
    }
    
     
  }
  
  
  public function executeEdit(sfWebRequest $request)
  {
  	 $this->setLayout('alika_layout');
     $this->mat = MaterialPeer::retrieveByPK(1);
     $this->form = new Type10Form($this->mat);
     
        if ($request->isMethod('post'))

    {
 
      $this->form->bind($request->getParameter('material'),$request->getFiles('material'));
      if ($this->form->isValid())
      {
      	  
         $this->form->save();
         $this->redirect('@homepage');
         }

    }
     
  }
  
	public function setDecorator()
	{

		$module = $this->getRequest()->getParameter('module');
		$action = $this->getRequest()->getParameter('action');
		
		$path_layout = sfConfig::get('sf_app_template_dir').'/layouts/'.sfConfig::get('app_name').'/'.$module.'.php';
		$path_template = sfConfig::get('sf_app_module_dir').'/'.$module.'/templates/'.sfConfig::get('app_name').'/'.$action.'Success.php';
		if(file_exists($path_layout))
		{ $l = 'layouts/'.sfConfig::get('app_name').'/'.$module; }
		else
		{ $l = sfConfig::get('app_name').'_layout'; }
		if(file_exists($path_template))
		{ $t = sfConfig::get('app_name').'/'.$action; }
		else
		{ $t = $action; }
			
	/*
     * Установка layout
     */	
			$this->setLayout ( $l );
		
     /*
     *  Устанавливаем шаблон
     */
		
			$this->setTemplate ( $t );
	}
  
}
